from typing import Optional

from pydantic import EmailStr
from sqlmodel import Field

from src.base.beans import PageParam
from src.base.constants import phone_pattern
from src.domain.base_model import TenantModel


class SysDeptBase(TenantModel):
    dept_id: Optional[int] = Field(primary_key=True, description="部门序号", sa_column_kwargs={"comment": "部门序号"})
    parent_id: Optional[int] = Field(description="父部门序号",
                                     sa_column_kwargs={"comment": "父部门序号", "server_default": "0"})
    dept_name: Optional[str] = Field(description="部门名称", sa_column_kwargs={"comment": "部门名称"})
    leader: Optional[str] = Field(description="负责人", sa_column_kwargs={"comment": "负责人"})
    phone: Optional[str] = Field(description="负责人电话", regex=phone_pattern,
                                 sa_column_kwargs={"comment": "负责人电话"})
    email: Optional[EmailStr] = Field(description="负责人邮箱", sa_column_kwargs={"comment": "负责人邮箱"})


class SysDept(SysDeptBase, table=True):
    __tablename__ = "sys_dept"
    __table_args__ = {'extend_existing': True, 'comment': '部门表'}


class SysDeptReq(SysDeptBase, PageParam):
    pass


class SysDeptResp(SysDeptBase):
    pass
